import openpyxl
import requests
from lxml import etree
proxies = {
    'http': 'socks5://127.0.0.1:10000',
    'https': 'socks5://127.0.0.1:10000'
}
headers = {
    'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,'
              'application/signed-exchange;v=b3;q=0.9',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) '
                  'Chrome/87.0.4280.141 Safari/537.36',
}
excel = openpyxl.load_workbook('C:/Users/Administrator/Desktop/video.xlsx')
sheet = excel['Sheet1']
rows = sheet.max_row
for i in range(2, rows+1):
    item = sheet.cell(i, 1).value
    res = requests.get(item, headers=headers, proxies=proxies, timeout=300)
    html_object = etree.HTML(res.text)
    media_url = html_object.xpath("//link[@rel='video_src']/@href")
    res.close()
    if(media_url):
        sheet.cell(i, 2).value = str(media_url[0])
        excel.save('C:/Users/Administrator/Desktop/video.xlsx')
    print("%s\t" %(media_url))
print("")
excel.close()